//
//  LearnMiscViewCtrl.m
//  MIDI
//
//  Created by 千行时线 on 15/9/14.
//  Copyright (c) 2015年 QXSX. All rights reserved.
//

#import "LearnMiscViewCtrl.h"
#import "LearnMiscCell.h"
#import "AppConfig.h"
#import "UIViewController+NavItem.h"
#import "UIViewController+Create.h"
#import "SearchCityViewController.h"
#import "MrMIDIViewCtrler.h"
#import "MIDIClubViewCtrler.h"
#import "SearchMIDIClubViewController.h"
#import "SearchCityViewController.h"
#import "BannerModel.h"
#import "UIButton+WebCache.h"
#import "QXNetWorkTool.h"
#import "APIAdress.h"
#import "MJExtension.h"
#import "MJRefresh.h"
#import "MyPageControl.h"
#import "SMPageControl.h"
#import "UserDataSingleton.h"
#import "SearchMIDIModel.h"
#import "SearchMIDISirModel.h"
#import "MrMIDISearchViewCtrler.h"
#import "CitylistModel.h"
#import "MBProgressHUD+YC.h"
#import "CommFunc.h"

@interface LearnMiscViewCtrl ()<UITableViewDelegate,UISearchBarDelegate,UITableViewDataSource,SelectExamCityDeletage,QXNetWorkToolDelegate,LearnMiscCellDelegate, UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;

@property (weak, nonatomic) IBOutlet UIView *learnwhomPageMark;

@property (weak, nonatomic) IBOutlet UIView *wherelearnPageMark;

@property (assign,nonatomic) NSInteger togglepage;

@property (weak, nonatomic) IBOutlet UITableView *myTableView;

@property (strong , nonatomic) UIBarButtonItem * cityButtonItem;

@property (copy , nonatomic) NSString *selectCity;

@property (weak, nonatomic) IBOutlet UIView *bigImageView;

@property (strong,nonatomic) NSTimer *timer;

@property (weak,nonatomic) UIScrollView *scrollView;

@property (strong,nonatomic) SMPageControl * pageControl;

@property (nonatomic,strong)NSMutableArray * bannerArray ;

@property (nonatomic,strong)UserDataSingleton * userData;

@property (nonatomic,assign) int nowClubPage;

@property (nonatomic,assign) int nowSirPage;

@property (nonatomic,strong) NSMutableArray * clubArray;

@property (nonatomic,strong) NSMutableArray * sirArray;

@property (nonatomic,copy) NSString *cityId;

@property (nonatomic,strong) LearnMiscCell *myCell;

@property (nonatomic , weak) IBOutlet UIImageView *loadingImage;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lunboHeight;

@property (weak, nonatomic) IBOutlet UIView *selectMarkView;

@property (nonatomic,assign) BOOL isDownBannerData;
@property (nonatomic,assign) BOOL isDownMIDIClub;
@property (nonatomic,assign) BOOL isDownMIDISir;


@end

@implementation LearnMiscViewCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _userData = [UserDataSingleton shareInstance];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    
    self.togglepage = 1;
    
    self.wherelearnPageMark.alpha = 1;
  
    self.learnwhomPageMark.alpha = 0;
    
    self.searchBar.delegate = self;
    
    self.bannerArray = [NSMutableArray array];
    
    self.clubArray = [NSMutableArray array];
    
    self.sirArray = [NSMutableArray array];

    self.nowClubPage = 1;
    
    self.nowSirPage = 1;
    
    self.isDownBannerData = NO;
    self.isDownMIDIClub = NO;
    self.isDownMIDISir = NO;
    
    [self configBigImage];
    
    self.searchBar.layer.borderColor = RGBA(230, 232, 231, 1).CGColor;
    self.searchBar.layer.borderWidth = 1.0f;
    
    UITextField *txfSearchField = [self.searchBar valueForKey:@"_searchField"];
    txfSearchField.textColor = [UIColor grayColor];
    
    txfSearchField.layer.cornerRadius = 15.0f;
    txfSearchField.layer.masksToBounds = YES;
    txfSearchField.layer.borderColor = RGBA(219, 219, 219, 1).CGColor;
    txfSearchField.layer.borderWidth = 1.0f;
    
    self.selectMarkView.layer.borderColor = RGBA(219, 219, 219, 1).CGColor;
    self.selectMarkView.layer.borderWidth = 1.0f;
    
    self.myTableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    
    self.myTableView.footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
 
    [self configNavigationItem];
    
    [self.searchBar setText:@"搜索"];
    
    [self downData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)configCoordinate
{
    self.cityId = _userData.curCityId;
    self.selectCity = _userData.cityName;
}

-(void) configNavigationItem
{
    [self configCoordinate];
    
    [self.tabBarController configNavigationBarTintColor:UIColorRGBA(0, 0, 0, 1)];
    [self.navigationController.navigationBar setBarTintColor:MIDIColorOfNavigationBar];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.tabBarController.navigationItem.title = @"学音乐";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],UITextAttributeFont,nil]];
    
//    UIButton *barButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 15)];
//    //    [self configNavigationRightString:@"筛选" textFont:[UIFont fontWithName:@"Hiragino Sans GB" size:13] andAction:^{[self pressRight];}];
//
//    [barButton setImage:[UIImage imageNamed:@"btn_navigation_back"] forState:UIControlStateNormal];
//    [barButton setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
//    
//    
//    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:barButton];
//    [barButton addTarget:self action:@selector(pressLeft:) forControlEvents:UIControlEventTouchUpInside];
//    [self.navigationItem setLeftBarButtonItem:barItem];
    
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithTitle:self.selectCity style:UIBarButtonItemStyleBordered target:self action:nil];
    UIFont *rightFont = [UIFont fontWithName:@"Hiragino Sans GB" size:13.0];
    UIColor *rightColor = UIColorRGBA(19, 208, 202, 1);
    
    
    NSDictionary * attributes = @{NSFontAttributeName:rightFont , NSForegroundColorAttributeName:rightColor };
    
    [rightBar setTitleTextAttributes:attributes forState:UIControlStateNormal];
    //[self.tabBarController.navigationItem setRightBarButtonItem:rightBar];
  
    [rightBar setEnabled:NO];
    
    UIButton *rightButton2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    
    [rightButton2 setImage:[UIImage imageNamed:@"ico_learnMusic_location"] forState:UIControlStateNormal];
    
    UIBarButtonItem * rightBar2 = [[UIBarButtonItem alloc]initWithCustomView:rightButton2];
    
    [rightButton2 addTarget:self action:@selector(pressRight:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.tabBarController.navigationItem setRightBarButtonItems : [NSArray arrayWithObjects:rightBar2,rightBar , nil]];
   
    self.cityButtonItem = rightBar;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.tabBarController.navigationItem setRightBarButtonItems:nil];
}

//右边城市按钮
-(void)pressRight:(UIButton *)sender
{
    SearchCityViewController * ctr = [SearchCityViewController create];
    
    ctr.delegate = self;
    
    [self.navigationController pushViewController:ctr animated:YES];
}

- (IBAction)didClickWhereLearnBtn:(id)sender {
    
    if (self.togglepage == 1)
    {
        return;
    }
    else
    {
        self.togglepage = 1;
      
        self.learnwhomPageMark.alpha = 0;
        
        self.wherelearnPageMark.alpha = 1;
    }
    
    [self.myTableView reloadData];
}
- (IBAction)didClickLearnWhomBtn:(id)sender {
    if (self.togglepage == 2)
    {
        return;
    }
    else
    {
        self.togglepage = 2;
       
        self.learnwhomPageMark.alpha = 1;
        
        self.wherelearnPageMark.alpha = 0;
    }
    
    [self.myTableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.togglepage == 1) {
        
        return _clubArray.count;
    }else {
    
        return _sirArray.count;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if ([[UIScreen mainScreen] bounds].size.width == 320)
//    {
//        if ([[UIScreen mainScreen] bounds].size.height == 568)
//        {
//            return 118;  //iphone4s、5、 5s
//        }
//    }
//    else if ([[UIScreen mainScreen] bounds].size.width == 375)
//    {
//        return 123;  //iphone6
//    }
//    else if ([[UIScreen mainScreen] bounds].size.width == 414)
//    {
//        return 130;  //iphone6 plus
//    }
//
//    return 130;
    
    return 123;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.myCell = [LearnMiscCell cellWithTableView:tableView];
    
    if (self.togglepage == 1) {
        
        if (_clubArray .count >0) {
         
            [self.myCell setMidiClub:_clubArray [indexPath.row]];
            self.myCell.midiSir = nil;
            self.myCell.delegate = self;
        }
    }else {
    
        if (_sirArray.count > 0)
        {
            self.myCell.midiSir  = _sirArray [indexPath.row];
            self.myCell.midiClub = nil;
            self.myCell.delegate = self;
        }
    }
    
    return self.myCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (self.togglepage == 1) {
      
        
        MIDIClubViewCtrler * vc = [MIDIClubViewCtrler create];
        SearchMIDIModel *data = self.clubArray[indexPath.row];
        if(data != nil)
        {
            [vc setSiteID:data.id];
        }
        [self.navigationController pushViewController:vc animated:YES];
        
        
    }else {
        
        MrMIDIViewCtrler * vc = [MrMIDIViewCtrler create];
        SearchMIDISirModel *data = self.sirArray[indexPath.row];
        if(data != nil)
        {
            [vc setMrMidiId:data.id];
        }
        [self.navigationController pushViewController:vc animated:YES];

      
    }
}

//设置每个cell的点击
- (void)configCell : (NSInteger)row  cell : (LearnMiscCell*)mycell
{
//    [mycell.button setTag:row];
//    [mycell.button addTarget:self action:@selector(clickCell:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)clickCell : (UIButton *)sender
{
//    if(self.togglepage == 1) //去哪学
//    {
//        MIDIClubViewCtrler * ctr = [MIDIClubViewCtrler create];
//        [self.navigationController pushViewController:ctr animated:YES];
//    }
//    else if(self.togglepage == 2) //找谁学
//    {
//        MrMIDIViewCtrler * ctr = [MrMIDIViewCtrler create];
//        [self.navigationController pushViewController:ctr animated:YES];
//    }
}

- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    
    SearchMIDIClubViewController * ctr = [SearchMIDIClubViewController create];

    
    [self.navigationController pushViewController:ctr animated:YES];

}

-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    if(self.togglepage == 1)
    {
        SearchMIDIClubViewController * ctr = [SearchMIDIClubViewController create];
        [self.navigationController pushViewController:ctr animated:YES];
    }
    else if(self.togglepage == 2)
    {   
        MrMIDISearchViewCtrler *obj = [MrMIDISearchViewCtrler create];
        obj.isShowMrMIDISearchBgAndScreening = NO;
        
        obj.curcity = self.cityId;
        obj.curcityName = self.selectCity;
        
        [self.navigationController pushViewController:obj animated:YES];
    }
    
    return NO;
}

-(void)setExamCity:(NSString *)city
{
    self.selectCity = city;
    
    NSMutableArray *data = [UserDataSingleton shareInstance].cityList;
    
    for (int i = 0; i < [data count]; ++i)
    {
        CitylistModel *model = [data objectAtIndex:i];
        
        if (model && [model.name isEqualToString:city])
        {
            if (![self.cityId isEqualToString:model.id])
            {
                self.cityId = model.id;
                self.selectCity = model.name;
                
                _nowClubPage = 1;
                _nowSirPage = 1;
                
                [_clubArray removeAllObjects];
                [_sirArray removeAllObjects];
                
                [self downMIDIClub];
                [self downMIDISir];
            }
            break;
        }
    }
}

#pragma mark 请求网络

- (void)downData{

    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD hideHUDForView:self.view];
    [MBProgressHUD hideHUDForView:self.view];
    
    if (!self.isDownBannerData)
    {
        [self downBannerData];
    }
 
    if (!self.isDownMIDIClub)
    {
        [self downMIDIClub];
    }
    
    if (!self.isDownMIDISir)
    {
        [self downMIDISir];
    }
}

- (void)downBannerData{
    
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    QXNetWorkTool * tool = [[QXNetWorkTool alloc]init];
    
    tool.QXNetWorkDelegate = self;
    
    [tool GetDataFromServerWithPostMethodandInterfaceName: LearnMusicBannerInterface andParameter:@[@{@"param":@""}] tag:1];
    
}

- (void)downMIDIClub{

    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    QXNetWorkTool * tool = [[QXNetWorkTool alloc]init];
    
    tool.QXNetWorkDelegate = self;
    
    
    [tool GetDataFromServerWithPostMethodandInterfaceName: ExamClubListInterface andParameter:@[@{@"club_city":self.cityId,@"nowpage":[NSString stringWithFormat:@"%d",_nowClubPage],@"pagesize":@"20"}] tag:2];
}

- (void)downMIDISir{

    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    QXNetWorkTool * tool = [[QXNetWorkTool alloc]init];
    
    tool.QXNetWorkDelegate = self;
    
    [tool GetDataFromServerWithPostMethodandInterfaceName: SearchMIDISirInterface andParameter:@[@{@"city_id":self.cityId,@"nowpage":[NSString stringWithFormat:@"%d",_nowSirPage],@"pagesize":@"20"}] tag:3];

}


- (void)GetSuccessResponse:(id)Response andTag:(int)tag{
    
    switch (tag) {
        case 1:
            [MBProgressHUD hideHUDForView:self.view];
            
            self.loadingImage.hidden = YES;
            
            for (NSDictionary *dict in Response) {
                
                BannerModel *banner = [BannerModel objectWithKeyValues:dict];
                
                [_bannerArray addObject:banner];
                
            }
            
            self.bannerArray = _bannerArray;
            
            self.isDownBannerData = YES;
            
            break;
      
        case 2:
            
            [MBProgressHUD hideHUDForView:self.view];
            for (NSDictionary *dict in Response)
            {
                SearchMIDIModel * model = [SearchMIDIModel objectWithKeyValues:dict];
                
                [_clubArray addObject:model];
            }
            
            self.isDownMIDIClub = YES;
            
            [self.myTableView reloadData];
            break;
       
        case 3:

            [MBProgressHUD hideHUDForView:self.view];
            for (NSDictionary *dict in Response)
            {
                SearchMIDISirModel * model = [SearchMIDISirModel objectWithKeyValues:dict];
                
                [_sirArray addObject:model];
            }
            
            self.isDownMIDISir = YES;
            
            [self.myTableView reloadData];
         
            break;
        default:
            break;
    }

    [MBProgressHUD hideHUDForView:self.view];
//    [MBProgressHUD hideHUDForView:self.view];
//    [MBProgressHUD hideHUDForView:self.view];
}

- (void)GetFailResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if (Response == nil)
        return;
    
    NSString *message = Response;
    
    [MBProgressHUD showError:message toView:self.view];
}


- (void)configBigImage{

    CGFloat width = kWindowWidth;
    
    //    CGFloat height = self.bigImageView.frame.size.height;
    
    self.lunboHeight.constant = [CommFunc getLunBoViewHeight];
    
    CGFloat height = self.lunboHeight.constant;
    
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    
    _scrollView = scroll;
    
//    scroll.backgroundColor = [UIColor blackColor];
    
    
    self.scrollView.pagingEnabled = YES ;
    
    self.scrollView.delegate = self ;
    
    _scrollView.showsVerticalScrollIndicator = FALSE;
    
    _scrollView.showsHorizontalScrollIndicator = FALSE;
    
    _pageControl = [[SMPageControl alloc]init];
    
    _pageControl.pageIndicatorImage = [UIImage imageNamed:@"ico_lunbo_white"];
    _pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"ico_lunbo_green"];
    
//    self.pageControl = [[MyPageControl alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];

    //self.pageControl.pageIndicatorTintColor = [UIColor clearColor];
  

//self.pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    
    [self.pageControl setBounds:CGRectMake(0, 0, 39, 39)];
    
    UIView *view = [[UIView alloc]init];
    
    [view setFrame:CGRectMake((width - view.frame.size.width)/2, height-20, 80, 40)];
    
    [view addSubview:self.pageControl];
    
   // [self.pageControl setBounds:CGRectMake(0, 0, 39, 39)];
    
    [self.bigImageView addSubview:scroll];
    
    [self.bigImageView addSubview:view];
    
    
}


-(void)addScrollViewTimer{
    
    _timer = [NSTimer timerWithTimeInterval:2 target:self selector:@selector(nextPage) userInfo:nil repeats:YES];
    
    [[NSRunLoop mainRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
}

-(void)setBannerArray:(NSMutableArray *)bannerArray{
    
    _bannerArray = bannerArray;
    
    if (_bannerArray.count>0) {
        
        [self addScrollViewTimer];
        
        NSUInteger imageCount = _bannerArray.count;
        
        CGFloat width = [UIScreen mainScreen].applicationFrame.size.width;
        
        CGFloat height = self.bigImageView.frame.size.height;
        
        self.pageControl.numberOfPages =imageCount;
        
        _scrollView.contentSize = CGSizeMake(width * imageCount, height);
        
        for (int i = 0; i < imageCount; i++) {
            
            CGFloat imageX = i * width;
            
            CGFloat imageY = 0.f;
            
            UIButton *imageBtn  = [[UIButton alloc]initWithFrame:CGRectMake(imageX, imageY, width, height)];
            
            imageBtn.tag = i;
            [imageBtn addTarget:self action:@selector(bannerOnClick:) forControlEvents:UIControlEventTouchUpInside];
            
            BannerModel *banner = _bannerArray[i];
            
            NSURL *url = [NSURL URLWithString:banner.img_url];
            
            [imageBtn sd_setBackgroundImageWithURL:url
                                          forState:UIControlStateNormal placeholderImage:
             [UIImage imageNamed:@"img_learn_misc_loading"]
             
                                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                                             
                [imageBtn setImage:image forState:UIControlStateNormal];
                                         }];
    
            imageBtn.tag = i;
            
            [self.scrollView addSubview: imageBtn];
            
            [imageBtn addTarget:self action:@selector(bannerOnClick:) forControlEvents:UIControlEventTouchUpInside];
            
        }
    }
}

-(void) bannerOnClick:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    
    BannerModel *banner = _bannerArray[btn.tag];
    NSURL *detailUrl = [NSURL URLWithString:banner.img_display_url	];
    
    UIViewController * vc = [[UIViewController alloc]init];
    UIWebView *webView = [[UIWebView alloc]initWithFrame:self.parentViewController.view.bounds];
    NSURLRequest *req = [NSURLRequest requestWithURL:detailUrl];
    [webView loadRequest:req];
    [vc.view addSubview:webView];
    [self.parentViewController		.navigationController pushViewController:vc animated:YES];
    [vc configNavigationBackAction:^{
        [vc.navigationController popViewControllerAnimated:YES];
    }];

    
}


-(void)nextPage
{
    
    if (_bannerArray >0) {
      
        int currentPage = self.pageControl.currentPage;
        
        currentPage ++ ;
        
        if (currentPage ==_bannerArray.count) {
            currentPage = 0;
        }
        
        CGFloat width = self.scrollView.frame.size.width ;
        
        CGPoint offset = CGPointMake(currentPage*width, 0.f);
        
        // self.scrollView.contentOffset = offset;
        // [self.scrollView setContentOffset:offset animated:(YES)];
        
        //动画
        [UIView animateWithDuration:.2f animations:^{
            
            self.scrollView.contentOffset = offset;
        }];
        
    }
    
}


-(void)removeScrollViewTimer{
    
    [_timer invalidate];
    _timer = nil ;
    
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGPoint offset =  self.scrollView.contentOffset;
    CGFloat offsetX = offset.x;
    CGFloat width = self.scrollView.frame.size.width ;
    int pageNum = ( offsetX + .5f*width )/ width ;
    
    self.pageControl.currentPage = pageNum ;
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    
    [self removeScrollViewTimer];
    
}

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    [self addScrollViewTimer];
}

- (void)loadNewData{
    
    if (self.togglepage == 1)
    {
        [_clubArray removeAllObjects];
        _nowClubPage = 1;
        [self downMIDIClub];
    }
    else
    {
        
        [_sirArray removeAllObjects];
        _nowSirPage = 1;
        [self downMIDISir];
    }

    [self.myTableView.header endRefreshing];
}

- (void)loadMoreData{
    
    if (self.togglepage == 1)
    {
        ++_nowClubPage;
        [self downMIDIClub];
    }
    else
    {
        ++_nowSirPage;
        [self downMIDISir];
    }
    
    [self.myTableView.footer endRefreshing];
    
}


- (void)pushToVC:(SearchMIDISirModel *)midiSir MidiClub:(SearchMIDIModel *)midiClub{

    if (midiSir) {
      
        MrMIDIViewCtrler * ctr = [MrMIDIViewCtrler create];
        [ctr setMrMidiId:midiSir.id];
        [self.navigationController pushViewController:ctr animated:YES];
        
        
    }else {
    
        
        MIDIClubViewCtrler * vc = [MIDIClubViewCtrler create];
        [vc setSiteID:midiClub.id];
        [self.navigationController pushViewController:vc animated:YES];
        

    
    }
}

@end























